Process, priority, , High
;CoordMode, Pixel, Screen
CoordMode, Mouse, Relative
gui, show, w400 h400 x850 y30, Pristontale Watcher
Gui, Add, Edit, R5 ReadOnly W200 vMyEdit
guicolor = 0
settimer, start, 200
settimer, colorz, 1000

Gui, Add, Slider, vSTMSlider cRed Vertical Invert, 10
GuiControl, Move, STMSlider, x10 y150 h150
Gui, Add, Text, cGreen vSTMText, 10
GuiControl, Move, STMText, x10 y300 w25

Gui, Add, Slider, vHPSlider Vertical Invert, 40
GuiControl, Move, HPSlider, x60 y150 h150
Gui, Add, Text, cRed vHPText, 40
GuiControl, Move, HPText, x60 y300 w25

Gui, Add, Slider, vMPSlider Vertical Invert, 10
GuiControl, Move, MPSlider, x110 y150 h150
Gui, Add, Text, cBlue vMPText, 10
GuiControl, Move, MPText, x110 y300 w25



Gui, Add, Text, vSlot1, Slot1`n||||||||||||||
Gui, Add, Text, vSlot2, Slot2`n||||||||||||||
Gui, Add, Text, vSlot3, Slot3`n||||||||||||||
GuiControl, Move, Slot1, x10 y330 h45 w45
GuiControl, Move, Slot2, x60 y330 h45 w45
GuiControl, Move, Slot3, x110 y330 h45 w45



colorz:
Gui, Font, cBlack
GuiControl, Font, Slot1
GuiControl, Font, Slot2
GuiControl, Font, Slot3
ChangeSlotColor(StaminaSlot, "30D500")
ChangeSlotColor(LifeSlot, "900000")
ChangeSlotColor(ManaSlot, "020090")
return

start:
If !FileExist("Locate.bmp"){
GuiControl,, MyEdit, File Locate.bmp Not Found!
return
}
If !FileExist("HP.txt "){
GuiControl,, MyEdit, File HP.txt  Not Found!
return
}
If !FileExist("MP.txt"){
GuiControl,, MyEdit, File MP.txt Not Found!
return
}
If !FileExist("STM.txt"){
GuiControl,, MyEdit, File STM.txt Not Found!
return
}

MouseGetPos,MouseX,MouseY

GuiControlGet, stmslidervalue,, STMSlider
GuiControlGet, hpslidervalue,, HPSlider
GuiControlGet, mpslidervalue,, MPSlider

GuiControl,, STMText, %stmslidervalue%
GuiControl,, HPText, %hpslidervalue%
GuiControl,, MPText, %mpslidervalue%


ifWinNotActive, Priston Tale
{
GuiControl,, MyEdit, "Priston Tale" Window Not Selected
if(guicolor > 0){
guicolor = 0
Gui, Color, ECE9D8, ECE9D8
}
return
}
SysGet, BorderX, 32
SysGet, MenubarY, 31
MenubarY += (BorderX + 1)
ImageSearch, LocateX, LocateY, %BorderX%, %MenubarY%, 800, 600, Locate.bmp


VarX := LocateX - 78
VarY := LocateY - 67
BarBottom := VarY + 121

;;;;check if mouse is in game screen-----
if(MouseY < MenubarY or MouseX < BorderX or MouseY > 480 or MouseX > 800){
;if(%MouseY% > %VarY%){
GuiControl,, MyEdit, Mouse is not in game screen area`nCursor X: %MouseX%`nCursor Y: %MouseY%`n`ndebug: %VarY%-%VarX%
return
}
;;;;;;if bar search fails it will be displayed after mouse location check------
if(LocateX == ""){
ImageSearch, LocateX, LocateY, %BorderX%, %MenubarY%, 800, 600, Locate.bmp
GuiControl,, MyEdit, Cant Locate Bars
sleep 100
return
}

;--------find what potions are in the slots---------
blankpot1 = 0x0B0A0B
blankpot2 = 0x0A090A
blankpot3 = 0x0F0D0F

MiniStm = 0x49C45D
MediumStm = 0x93E3A1
GreatStm = 0x40C055
MysticStm = 0x4FC763

MiniLife = 0x181890
MedLife = 0x6B6BCB
GreatLife = 0x101089
MysticLife = 0x1E1E95

MiniMana = 0x961818
MedMana = 0xC66060
GreatMana = 0x8B1717
MysticMana = 0x901F1F


PotionY := 110+VarY
Potion1X := 220+VarX
Potion2X := 246+VarX
Potion3X := 272+VarX

PixelGetColor, Slot1, Potion1X, PotionY, Slow
PixelGetColor, Slot2, Potion2X, PotionY, Slow
PixelGetColor, Slot3, Potion3X, PotionY, Slow


CheckPotion(Slot1a, Slot2a, Slot3a, Potion1, Potion2, Potion3, Potion4){
;msgbox %Slot1a%, %Slot2a%, %Slot3a%, %Potion1%, %Potion2%, %Potion3%, %Potion4%
if(Slot1a = Potion1){
return 1
}else if(Slot2a = Potion1){
return 2
}else if(Slot3a = Potion1){
return 3
}else if(Slot1a = Potion2){
return 1
}else if(Slot2a = Potion2){
return 2
}else if(Slot3a = Potion2){
return 3
}else if(Slot1a = Potion3){
return 1
}else if(Slot2a = Potion3){
return 2
}else if(Slot3a = Potion3){
return 3
}else if(Slot1a = Potion4){
return 1
}else if(Slot2a = Potion4){
return 2
}else if(Slot3a = Potion4){
return 3
}else{
return X
}

}


StaminaSlot := CheckPotion(Slot1, Slot2, Slot3, MiniStm, MediumStm, GreatStm, MysticStm)
LifeSlot := CheckPotion(Slot1, Slot2, Slot3, MiniLife, MedLife, GreatLife, MysticLife)
ManaSlot := CheckPotion(Slot1, Slot2, Slot3, MiniMana, MedMana, GreatMana, MysticMana)
;change box colors

ChangeSlotColor(slot, color){
Gui, Font, c%color%
if(slot == 1){
GuiControl, Font, Slot1
}else if(slot == 2){
GuiControl, Font, Slot2
}else if(slot == 3){
GuiControl, Font, Slot3
}

}

;------------end potion search----------------




;--------function to check bar values--------
BarValue(BarX, BarY, BarFile)
{
startloop := BarY
stmval = 0
Loop, Read, %BarFile%
{

PixelGetColor, OutputVar, BarX, startloop, Slow

if(OutputVar != A_LoopReadLine){
break
}
startloop -= 1
stmval := BarY - startloop

}
return stmval
}
;----------end function----------



;find HP percent
HPx := VarX + 39
HPy := VarY + 121
HP := BarValue(HPx,HPy,"HP.txt")
HPpercent := Round(100 / (93 / HP))
if(%HPpercent% < %hpslidervalue%){
GuiControl,,MyEdit, Using HP %LifeSlot%
Send {%LifeSlot% Down}
guicolor = 1
Gui, Color, 900000, 900000
Send {%LifeSlot% Up}
return
}
;SendMode InputThenPlay
;find STM percent
STMx := varX + 15
STMy := varY + 121
STM := BarValue(STMx,STMy,"STM.txt")
STMpercent := Round(100 / (75 / STM))
if(STMpercent < stmslidervalue){
GuiControl,,MyEdit, Using Stamina %StaminaSlot%
SendEvent {%StaminaSlot% Down}
guicolor = 2
Gui, Color, 308500, 308500
SendEvent {%StaminaSlot% Up}
return
}


;find MP percent
MPx := varX + 192
MPy := varY + 121
MP := BarValue(MPx,MPy,"MP.txt")
MPpercent := Round(100 / (93 / MP))
if(MPpercent < %mpslidervalue%){
GuiControl,,MyEdit, Using MP %ManaSlot%
Send {%ManaSlot% Down}
guicolor = 3
Gui, Color, 020090, 020090
Send {%ManaSlot% Up}
return
}


if(guicolor > 0){
guicolor = 0
Gui, Color, ECE9D8, ECE9D8
}


GuiControl,,MyEdit, STM: %STMpercent%`%`nHP: %HPpercent%`%`nMP: %MPpercent%`%

;GuiControl,,MyEdit, %data%1

return





^d::
Send HP: %HPpercent%`% MP: %MPpercent%`% STM: %STMpercent%`%
Return

GuiClose:
ExitApp